//
//  LYRadioViewController.m
//  MusicMV
//
//  Created by dllo on 16/3/21.
//  Copyright © 2016年 Eternity. All rights reserved.
//

#import "LYRadioViewController.h"
#import <AFNetworking.h>
#import <MediaPlayer/MediaPlayer.h>
#import "LHYDownLoadManager.h"
#import "AFHTTPRequestOperation.h"
#import "AFHTTPRequestOperationManager.h"
#import <AVFoundation/AVFoundation.h>
@interface LYRadioViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *leftTableView;/**< 左边的tableView */
@property (nonatomic, retain) UITableView *rightTableView;/**< 右边的tableView */
@property (nonatomic, retain) UITableView *buttomTableView; /**< 下边的放播放的tableView */
@property (nonatomic, retain) NSMutableArray *titleArr; /**< 标题的数组 */
@property (nonatomic, retain) NSMutableArray *songArr; /**< 右侧歌曲的数组 */

@property (nonatomic, retain) UIImageView *imgView; /**< 底部的图片 */
@property (nonatomic, retain) UILabel *singLabel; /**< 歌曲的名字 */
@property (nonatomic, retain) UILabel *authorLabel; /**< 作者的名字 */
@property (nonatomic, retain) UIImageView *playView; /**< 播放的按钮 */
@property (nonatomic, retain) UIImageView *listImage; /**< 列表的按钮 */
@property (nonatomic, assign) BOOL isSelect; /**< 判断是第几次点击 */
@property (nonatomic, retain) NSString *idStr; /**< 数据的id */
@property (nonatomic, retain) NSMutableArray *playArr;/**< 音乐播放的数组 */

@property (nonatomic, retain) UITableView *listTableView; /**< 列表的tableview */
@property (nonatomic, retain) UIView *listView; /**< 列表弹出的view */
@property (nonatomic, assign) BOOL isClick; /**< 判断列表是否点击 */
@property (nonatomic, assign) NSInteger selectIndex;/**< 用来记录tableview选中哪一行 */
@property (nonatomic, assign) NSInteger index; /**< 用来记录播放的音乐的下标 */
@property (nonatomic, assign) BOOL isPlay; /**< 判断右边的tableview的播放按钮是什么状态 */

@property (nonatomic, assign) BOOL isIndex; /**< 记录哪个按钮是播放状态 */

//@property (nonatomic, retain) UISlider *timeSlider;
@property (nonatomic, retain) UIView *musicView; /**< 点击图片弹出的view */

@property (nonatomic , strong) UIVisualEffectView *visualEfView; /**< 毛玻璃 */

@property (nonatomic, retain) UIImageView *bigImgView;/**< 播放页面的滚动图片 */

@property (nonatomic, assign) BOOL isFirst; /**< 点击图片判断是第几次点击 */



@property (nonatomic, retain) UILabel *MusicCurrentTimer; /**< 歌曲当前时间 */
@property (nonatomic, retain) UILabel *MusicAllTimer; /**< 歌曲总时间 */

@property (nonatomic, retain) UISlider *timerSlder; /**< 时间的滑竿 */
@property (nonatomic, retain) UIButton *likeButton; /**< 喜欢的按钮 */
@property (nonatomic, retain) UIButton *upButton; /**< 上一首按钮 */
@property (nonatomic, retain) UIButton *downButton; /**< 下一首按钮 */
@property (nonatomic, retain) UILabel *singerLabel; /**< 歌手的名字 */
@property (nonatomic, retain) UILabel *songLabel; /**< 歌曲的名字 */

@property (nonatomic, assign) CGFloat timer;
@property (nonatomic, assign) BOOL play; /**< 是否播放第一首歌曲 */
@property (nonatomic, assign) BOOL first;



@property (nonatomic,retain) NSURLSessionDownloadTask *downLoadTask; /**< 下载任务 */

@property (nonatomic, retain) UIProgressView *progressV;

@property (nonatomic, strong) NSString *filePath; /**< 文件路径 */
@property (nonatomic, assign, getter=isNowDownload) BOOL nowDownload;
@property (nonatomic, strong) AFHTTPRequestOperation *operation1;
@property (nonatomic, retain) NSMutableArray *arrDownLoad;
@property (nonatomic, assign) BOOL isDownLoad;
@property (nonatomic, retain) UIButton *loadButton;
@property (nonatomic, retain) UIButton *didDownButton;
@property (nonatomic, retain) UIView *backView;

@end

@implementation LYRadioViewController


- (void)dealloc {
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"huan" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"huan1" object:nil];
    
    _leftTableView.delegate = nil;
    _leftTableView.dataSource = nil;
    _rightTableView.delegate = nil;
    _rightTableView.dataSource = nil;
    
    _listTableView.delegate = nil;
    _listTableView.dataSource = nil;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.playArr = [NSMutableArray array];
    self.titleArr = [NSMutableArray array];
    self.songArr = [NSMutableArray array];
    [self createView];
    
    [self dataHandle];
    
    _isSelect = YES;
    _isClick = YES;
    _selectIndex = 0;
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeAction:) name:@"huan" object:nil];
    
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bottomChangeAction:) name:@"huan1" object:nil];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(15 * wt, 15 * ht, 20 * wt, 20 * wt);
    [button setBackgroundImage:[UIImage imageNamed:@"goBack"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    
   
    
}


- (void)buttonAction:(UIButton *)button {
    
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

#pragma mark - 通知方法
- (void)changeAction:(NSNotification *)notification {
    
    
    LYDayMusicModel *model = notification.object;
    [_bigImgView sd_setImageWithURL:[NSURL URLWithString:model.picUrl]];
    _singerLabel.text = [NSString stringWithFormat:@"作者 : %@", model.singerName];
    _songLabel.text = model.name;
}

- (void)bottomChangeAction:(NSNotification *)notification {
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSDictionary *dic = [defaults objectForKey:@"model1"];
    [_imgView sd_setImageWithURL:[NSURL URLWithString:dic[@"pic"]]];
    _authorLabel.text = dic[@"singName"];
    _singLabel.text = dic[@"singerName"];
    
}


// 页面布局
- (void)createView {
    
    // 左边的tableView
    self.leftTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH / 4 + 5 * wt, HEIGHT - 64 - 49) style:UITableViewStylePlain];
    [self.view addSubview:_leftTableView];
    _leftTableView.delegate = self;
    _leftTableView.dataSource = self;
    _leftTableView.backgroundColor = [UIColor lightGrayColor];
    _leftTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_leftTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"leftTableView"];
    
    //右边的tableView
    self.rightTableView = [[UITableView alloc] initWithFrame:CGRectMake(WIDTH / 4 + 5 * wt, 0, WIDTH / 4 * 3 - 10 * wt, HEIGHT - 64 - 49) style:UITableViewStylePlain];
    [self.view addSubview:_rightTableView];
    _rightTableView.delegate = self;
    _rightTableView.dataSource = self;
    
    _rightTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_rightTableView registerClass:[LYDayRightTableViewCell class] forCellReuseIdentifier:@"rightTableView"];
    _rightTableView.showsVerticalScrollIndicator = NO;
    
    // 底部的tableView
    self.buttomTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.rightTableView.frame.size.height, WIDTH, HEIGHT - self.rightTableView.frame.size.height) style:UITableViewStylePlain];
    
    [self.view addSubview:_buttomTableView];
    
    
    _buttomTableView.delegate = self;
    _buttomTableView.dataSource = self;
    
    [_buttomTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"buttomTableView"];
    
    self.imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10 * wt, (49 - 40 * wt) / 2, 40 * wt, 40 * wt)];
    _imgView.layer.cornerRadius = 20 * wt;
    _imgView.layer.masksToBounds = YES;
    
    [_buttomTableView addSubview:_imgView];
//    _imgView.backgroundColor = [UIColor yellowColor];
    _imgView.image = [UIImage imageNamed:@"00.jpg"];
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    _imgView.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *imgTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imgTapAction:)];
    [_imgView addGestureRecognizer:imgTap];
    
    
    // 底下歌曲的名字
    self.singLabel = [[UILabel alloc] initWithFrame:CGRectMake(_imgView.frame.size.width + _imgView.frame.origin.x + 15 * wt, 5 * ht, 200 * wt, 25 * ht)];
    [self.buttomTableView addSubview:_singLabel];
    _singLabel.font = [UIFont systemFontOfSize:15];
    _singLabel.textColor = [UIColor whiteColor];
    
    
    // 底下歌手的名字
    self.authorLabel = [[UILabel alloc] initWithFrame:CGRectMake(_imgView.frame.size.width + _imgView.frame.origin.x + 15 * wt, _singLabel.frame.size.height, 150 * wt, 25 * ht)];
    [self.buttomTableView addSubview:_authorLabel];
    _authorLabel.font = [UIFont systemFontOfSize:14];
    _authorLabel.textColor = [UIColor lightGrayColor];
   
    NSLog(@"%@", [[NSUserDefaults standardUserDefaults] objectForKey:@"model1"]);
    
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"model1"] != NULL) {
        
        NSDictionary *dic = [defaults objectForKey:@"model1"];
        [_imgView sd_setImageWithURL:[NSURL URLWithString:dic[@"pic"]]];
         _authorLabel.text = dic[@"singName"];
        _singLabel.text = dic[@"singerName"];
    }
    else {
        _imgView.image = [UIImage imageNamed:@"222"];
        _singLabel.text = @"欢迎";
        
    }

    
    // 播放的
    self.playView = [[UIImageView alloc] init];
    [self.buttomTableView addSubview:_playView];
    _playView.frame = CGRectMake(WIDTH - 100 * wt, (49 - 30 * wt) / 2, 30 * wt, 30 * wt);
    _playView.image = [UIImage imageNamed:@"iconfont-bofanganniu"];
    _playView.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *playTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(playTapAction:)];
    [_playView addGestureRecognizer:playTap];
    
    
    // 歌曲列表
    self.listImage = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH - 50 * wt, (49 - 30 * wt) / 2, 30 * wt, 30 * wt)];
    [self.buttomTableView addSubview:_listImage];
    _listImage.image = [UIImage imageNamed:@"iconfont-bofangliebiao"];
    _listImage.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [_listImage addGestureRecognizer:tap];
    
    
}



#pragma mark - tableView dalegate & datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (tableView == _leftTableView) {
        return _titleArr.count;
    }else if (tableView == _rightTableView) {

        return self.songArr.count;
    }else if (tableView == _listTableView){
        return _playArr.count;
    }else {
        return 1;
    }
    
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (tableView == _listTableView) {
        return 1;
    }else {
        return 1;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (tableView == _listTableView) {
        return 30 * ht;
    }else {
        return 0;
    }
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    if (tableView == _listTableView) {
        
        return @"正在播放";
    }else {
        return nil;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    // 左边的tableView
    if (tableView == _leftTableView) {
        
        LYDayTitleModel *model = _titleArr[indexPath.row];
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"leftTableView"];
        cell.textLabel.text = model.tag_type_name;
        cell.textLabel.textColor =[UIColor blackColor];
        
        // 判断是当前的行数 是就变色
        if (_selectIndex == indexPath.row) {
            cell.textLabel.textColor = [UIColor orangeColor];
            
        }else {
            cell.textLabel.textColor = [UIColor blackColor];
        }

        cell.backgroundColor = [UIColor lightGrayColor];
        return cell;
        
        // 右边的tableView
    }else if (tableView == _rightTableView) {
        
        LYDayRightTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"rightTableView"];
        LYDayRightModel *model = _songArr[indexPath.row];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.model = model;
        
//        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        
                // 判断是当前的行数 是就变
        if (model.isClick) {
            cell.img.image = [UIImage imageNamed:@"iconfont-zanting"];
        }else {
            cell.img.image = [UIImage imageNamed:@"iconfont-yinlebofang"];
        }
        


        return cell;
        
        
        // 列表的tableView
    }else if (tableView == _listTableView){
        
        LYListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"listTableView"];
            LYDayMusicModel *model = _playArr[indexPath.row];
            cell.model = model;
        if (indexPath.row == 0) {
            cell.numLabel.text = @"1";
        }else if (indexPath.row == 1) {
            cell.numLabel.text = @"2";
        }else if (indexPath.row == 2) {
            cell.numLabel.text = @"3";
        }else if (indexPath.row == 3) {
            cell.numLabel.text = @"4";
        }else {
            cell.numLabel.text = @"5";
        }
            
            NSLog(@"%@", model.name);
        return cell;
    }else {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"buttomTableView"];
        cell.backgroundColor = [UIColor blackColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == _leftTableView) {
        return 50 * ht;
    }else if (tableView == _rightTableView) {
        return 150 * ht;
    }else if (tableView == _listTableView){
        return 50 * ht;
    }else {
        return 75 * ht;
    }
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    // 左边的tableView的点击方法
    if (tableView == _leftTableView) {
        
        LYDayTitleModel *model = _titleArr[indexPath.row];
        _songArr = [NSMutableArray arrayWithArray:model.data];
        
        // 进来的改变成黑色
        NSIndexPath *index = [NSIndexPath indexPathForItem:_selectIndex inSection:0];
        UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:index];
        cell.selectionStyle = UITableViewScrollPositionNone;
        cell.textLabel.textColor = [UIColor blackColor];
        // 创建新的cell 记录点击是哪行  变成红色
        UITableViewCell *newCell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
        newCell.selectionStyle = UITableViewScrollPositionNone;
        newCell.textLabel.textColor = [UIColor orangeColor];
        _selectIndex = indexPath.row;
        [_rightTableView reloadData];
        
       // 右边tableView的点击方法
    }else if (tableView == _rightTableView) {
        
        LYDayRightTableViewCell *cell = (LYDayRightTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
        LYDayRightModel *model = _songArr[indexPath.row];
        // 暂停状态
        if (![[PlayMusicHelp share] isPlay]) {
            [self imgViewStart];

            self.idStr = model.tag_id;
            [self musicDataHandle];
            
            cell.img.image = [UIImage imageNamed:@"iconfont-zanting"];
            _playView.image = [UIImage imageNamed:@"iconfont-bofangqizanting"];
            
            _isPlay = YES;
            model.isClick = YES;
            
            [_leftTableView reloadData];
            [_rightTableView reloadData];
            
            _isIndex = indexPath.row;
            [PlayMusicHelp share].num = indexPath;
            
            [[NSUserDefaults standardUserDefaults] setInteger:indexPath.row forKey:@"row"];
            _play = YES;
            _first = YES;

            // 播放状态
        }else  {
            
            NSLog(@"%ld", [PlayMusicHelp share].num.row);
            LYDayRightTableViewCell *lastCell = (LYDayRightTableViewCell *)[tableView cellForRowAtIndexPath:[PlayMusicHelp share].num];
            if (indexPath.row != [PlayMusicHelp share].num.row) {
                NSLog(@"jlkkdl");
                [LY_sharePlayeMusicHelp pause];
                lastCell.img.image = [UIImage imageNamed:@"iconfont-yinlebofang"];
                cell.img.image = [UIImage imageNamed:@"iconfont-zanting"];
                _playView.image = [UIImage imageNamed:@"iconfont-bofangqizanting"];
                self.idStr = model.tag_id;
                [self musicDataHandle];
                
                [PlayMusicHelp share].num = indexPath;
                
                _play = YES;
                
                
            }else {
                
                
                
                if ([PlayMusicHelp share].num.row == indexPath.row) {
                    
                    cell.img.image = [UIImage imageNamed:@"iconfont-yinlebofang"];
                    _playView.image = [UIImage imageNamed:@"iconfont-bofanganniu"];
                    [LY_sharePlayeMusicHelp pause];
                    [self imgViewStop];
                    
                }else {
                    
                    
                    lastCell.img.image = [UIImage imageNamed:@"iconfont-yinlebofang"];
                    
                    cell.img.image = [UIImage imageNamed:@"iconfont-zanting"];
                    _playView.image = [UIImage imageNamed:@"iconfont-bofangqizanting"];
                    model.isClick = NO;
                    [LY_sharePlayeMusicHelp pause];
                    [self imgViewStop];
                    
                }

            }
            
            
            
        }
        
        //列表的点击方法
    }else if (tableView == _listTableView) {
        
        LYDayMusicModel *model = _playArr[indexPath.row];
        NSLog(@"%@", model.audition);
        [LY_sharePlayeMusicHelp playMusicMp3Url:model.audition];
        
        // 图片赋值 旋转
        [_imgView sd_setImageWithURL:[NSURL URLWithString:model.picUrl]];
        [self imgViewStart];
        
        _singLabel.text = model.name;
        _authorLabel.text = model.singerName;
        
        _index = indexPath.row;
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"huan" object:model];
        
       NSDictionary *dic= [NSDictionary dictionaryWithObjectsAndKeys:model.singerName, @"singName", model.name, @"singerName", model.picUrl, @"pic", model.audition, @"music", model.Baudition, @"Bmusic", model.Haudition, @"Hmusic", nil];
        NSLog(@"%@", dic[@"singName"]);
        [[NSUserDefaults standardUserDefaults] setObject:dic forKey:@"model1"];
//        [[NSUserDefaults standardUserDefaults] setObject:model.Baudition forKey:@"B"];
//        [[NSUserDefaults standardUserDefaults] setObject:model.Haudition forKey:@"H"];
        [_didDownButton setHidden:YES];
        [_loadButton setHidden:YES];
        [self noOrYesDownLoad];


    // 点击下面的进入下一页
    }else {
        
    }
}

// 列表的触摸方法
- (void)tapAction:(UITapGestureRecognizer *)tap {
    
    if (_isClick) {
        
        self.listView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT / 2 - 50 * ht)];
        [self.view addSubview:_listView];
        _listView.backgroundColor = [UIColor blackColor];
        _listView.alpha = 0.2;
        
        _listView.userInteractionEnabled = YES;
        
        self.listTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, HEIGHT / 2 - 50 * ht, WIDTH - 5 * wt, HEIGHT / 2 - 10 * ht)];
        
        [self.view addSubview:_listTableView];
        
        _listTableView.delegate = self;
        _listTableView.dataSource = self;
        _listTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        [_listTableView registerClass:[LYListTableViewCell class] forCellReuseIdentifier:@"listTableView"];
    }else {
        [_listView setHidden:YES];
        [_listTableView setHidden:YES];
    }
    
    _isClick = !_isClick;
}

/** 播放按钮的点击方法 */
- (void)playTapAction:(UITapGestureRecognizer *)tap {
    
    // 暂停状态下
    if (![LY_sharePlayeMusicHelp isPlay]) {
        
        
        LYDayRightModel *model = _songArr[_index];
        self.idStr = model.tag_id;
        
        [self musicDataHandle];
        
        if (_first == NO) {
            
            NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
            NSDictionary *dic = [defaults objectForKey:@"model1"];
            [LY_sharePlayeMusicHelp playMusicMp3Url:dic[@"music"]];
            [self performSelector:@selector(startAnimate) withObject:self afterDelay:0.1];
            
            _first = YES;
            
        }else {
            
            [LY_sharePlayeMusicHelp seekToTime:_timerSlder.value];
        }
        _playView.image = [UIImage imageNamed:@"iconfont-bofangqizanting"];
        
        [self imgViewStart];
        
        [self bigImgViewStart];
        
 
        // 播放状态下
    }else {
        
        
        _playView.image = [UIImage imageNamed:@"iconfont-bofanganniu"];
        [LY_sharePlayeMusicHelp pause];
        NSLog(@"%f", _timerSlder.value);
        
        _timer = _timerSlder.value;
        
        [self imgViewStop];
        [self bigImgViewStop];
        
        
    }
    
   
}


// 判断是否下载过
- (void)noOrYesDownLoad {
    
    
    NSMutableArray *arrTitle = [NSMutableArray array];
    self.arrDownLoad = [self getArr];
    
    for (NSDictionary *dic in self.arrDownLoad) {
        
        [arrTitle addObject:dic[@"singerName"]];
        
    }
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSDictionary *dic = [defaults objectForKey:@"model1"];
    
    if ([arrTitle containsObject:dic[@"singerName"]]) {
        
//        self.isDownLoad = YES;
        
        _loadButton.alpha = 0;
        [_loadButton setHidden:YES];

        self.didDownButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.visualEfView addSubview:_didDownButton];
        _didDownButton.frame = CGRectMake(WIDTH - 80 * wt, _singerLabel.frame.origin.y, 20 * wt, 20 * wt);
        [_didDownButton setBackgroundImage:[UIImage imageNamed:@"iconfont-liangkehongxin"] forState:UIControlStateNormal];
        [_didDownButton addTarget:self action:@selector(didDownLoad:) forControlEvents:UIControlEventTouchUpInside];
    }else {
//        self.isDownLoad = NO;
        
        _didDownButton.alpha = 0;
        [_didDownButton setHidden:YES];
        self.loadButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.visualEfView addSubview:_loadButton];
        _loadButton.frame = CGRectMake(WIDTH - 80 * wt, _singerLabel.frame.origin.y, 20 * wt, 20 * wt);
        [_loadButton setBackgroundImage:[UIImage imageNamed:@"iconfont-download"] forState:UIControlStateNormal];
        [_loadButton addTarget:self action:@selector(downLoad:) forControlEvents:UIControlEventTouchUpInside]
        ;
        
       
    }


    
}

/** 轻拍下面的图片弹出的页面 并且做出逻辑判断 */
- (void)imgTapAction:(UIGestureRecognizer *)tap {
    

    LYDayRightModel *model = _songArr[_index];
    self.idStr = model.tag_id;
    
    [self musicDataHandle];
    
    
    
    if (_isFirst == NO) {
        
        
        
        if (![LY_sharePlayeMusicHelp isPlay]) {
            [LY_sharePlayeMusicHelp pause];
            
            NSLog(@"%f", _timer);
            _timerSlder.value = _timer;
        }
        else {
            
            [LY_sharePlayeMusicHelp pause];
            
            
            [LY_sharePlayeMusicHelp seekToTime:_timerSlder.value];
        }
    
    
    
    [self performSelector:@selector(startAnimate) withObject:self afterDelay:0.1];
        
        [_listTableView setHidden:YES];
        
        [_leftTableView setHidden:YES];
        [_rightTableView setHidden:YES];
    
    UIImageView *backImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH - 40 * wt, HEIGHT - 50 * ht - 75 * ht)];
        NSDictionary *dic = [[NSUserDefaults standardUserDefaults] objectForKey:@"model1"];
        [backImageView sd_setImageWithURL:[NSURL URLWithString:dic[@"pic"]] placeholderImage:[UIImage imageNamed:@"00.jpg"]];
    
    backImageView.userInteractionEnabled = YES;
    
    // 毛玻璃
    self.visualEfView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
    _visualEfView.frame = CGRectMake(0, 0, WIDTH - 40 * wt, HEIGHT - 50 * ht - 75 * ht);
    _visualEfView.alpha = 1;
    _visualEfView.userInteractionEnabled = YES;
    
   self.backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH - 40 * wt, HEIGHT - 50 * ht - 75 * ht)];
    _backView.backgroundColor = [UIColor blackColor];
    _backView.alpha = 0.4;
    [backImageView addSubview:_backView];
    [backImageView addSubview:_visualEfView];
    
    _rightTableView.alpha = 0.2;
    _leftTableView.alpha = 0.2;
    self.musicView = [[UIView alloc] initWithFrame:CGRectMake(20 * wt, 0, WIDTH - 40 * wt, HEIGHT - 50 * ht - 75 * ht)];
    [self.view addSubview:_musicView];
    
    [_musicView addSubview:backImageView];
    
   self.bigImgView = [[UIImageView alloc] initWithFrame:CGRectMake((_musicView.frame.size.width - 200 * wt) / 2, 50 * ht, 200 * wt, 200 * wt)];
    [self.musicView addSubview:_bigImgView];
    // 专辑图片
    [_bigImgView sd_setImageWithURL:[NSURL URLWithString:dic[@"pic"]]];
    // 设置圆角
    _bigImgView.layer.cornerRadius = 200 * wt / 2.0;
    // 裁掉边框
    _bigImgView.layer.masksToBounds = YES;
    
    //加边框
    _bigImgView.layer.borderWidth = 3;
    _bigImgView.layer.borderColor = [UIColor cyanColor].CGColor;
        
        [self createBigView];
        
        
        LY_sharePlayeMusicHelp.playToEndBlock = ^(){
            NSLog(@"播放完我单例的观察者会观察到 就会调用block 走这个方法, 播放完在这里做你想做的");
            
            [self imgViewStop];
            
            _playView.image = [UIImage imageNamed:@"iconfont-bofanganniu"];
            
            
            _index++;
            
            if (_index < _playArr.count) {
                
                _playView.image = [UIImage imageNamed:@"iconfont-bofangqizanting"];
                LYDayMusicModel *model = _playArr[_index];
                
                [self change:model];
                
                [[NSNotificationCenter defaultCenter] postNotificationName:@"huan" object:model];
               NSDictionary *dic= [NSDictionary dictionaryWithObjectsAndKeys:model.singerName, @"singName", model.name, @"singerName", model.picUrl, @"pic", model.audition, @"music", model.Baudition, @"Bmusic", model.Haudition, @"Hmusic", nil];
                NSLog(@"%@", dic[@"singName"]);
                [[NSUserDefaults standardUserDefaults] setObject:dic forKey:@"model1"];
                
                [[NSNotificationCenter defaultCenter] postNotificationName:@"huan1" object:dic];
//                [[NSUserDefaults standardUserDefaults] setObject:model.Baudition forKey:@"B"];
//                [[NSUserDefaults standardUserDefaults] setObject:model.Haudition forKey:@"H"];

            }
            
        };

    
    }else {
        _rightTableView.alpha = 1;
        _leftTableView.alpha = 1;
        [_leftTableView setHidden:NO];
        [_rightTableView setHidden:NO];
        [_musicView removeFromSuperview];
        [_songLabel setHidden:YES];
        [_singerLabel setHidden:YES];
        
    }
    
    _isFirst = !_isFirst;
    
    
    
}

/** 创建弹出的播放页面的控件 */
- (void)createBigView {
    
    // 滑竿
    self.timerSlder = [[UISlider alloc] initWithFrame:CGRectMake(60 * wt, _bigImgView.frame.size.height + _bigImgView.frame.origin.y + 20 * ht, WIDTH - 130 * wt - 40 * wt, 20 * ht)];
    [self.visualEfView addSubview:_timerSlder];
    [_timerSlder addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
    
    // 文字的大小, 描述文字大小的信息
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17], NSFontAttributeName, nil];
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSDictionary *dic2 = [defaults objectForKey:@"model1"];
    // 歌手的名字
    CGRect rect1 = [dic2[@"singName"] boundingRectWithSize:CGSizeMake(0, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    self.singerLabel = [[UILabel alloc] initWithFrame:CGRectMake((WIDTH - rect1.size.width - 60 * ht) / 2, _timerSlder.frame.size.height + _timerSlder.frame.origin.y + 10 * ht, rect1.size.width + 60 * wt, 40 * ht)];
    [self.visualEfView addSubview:_singerLabel];
    _singerLabel.text = [NSString stringWithFormat:@"作者 : %@", dic2[@"singName"]];
    _singerLabel.textColor = [UIColor whiteColor];
    
    
    CGRect rect = [dic2[@"singerName"] boundingRectWithSize:CGSizeMake(0, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    self.songLabel = [[UILabel alloc] initWithFrame:CGRectMake((WIDTH - rect.size.width) / 2, 5 * ht, rect.size.width, 40 * ht)];
    [self.visualEfView addSubview:_songLabel];
    _songLabel.text = dic2[@"singerName"];
    
    
    [self noOrYesDownLoad];
    
    //歌曲当前时间
    self.MusicCurrentTimer = [[UILabel alloc] initWithFrame:CGRectMake(5 * wt, _bigImgView.frame.size.height + _bigImgView.frame.origin.y + 10 * ht, 60 * wt, 40 * ht)];
    [self.visualEfView addSubview:self.MusicCurrentTimer];
    self.MusicCurrentTimer.textColor = [UIColor grayColor];
    self.MusicCurrentTimer.text = @"00:00";
    self.MusicCurrentTimer.font = [UIFont systemFontOfSize:17];
    
    //歌曲总时间
    self.MusicAllTimer = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH - 70 * wt - 30 * wt, _bigImgView.frame.size.height + _bigImgView.frame.origin.y + 10 * ht, 60 * wt, 40 * ht)];
    [self.visualEfView addSubview:self.MusicAllTimer];
    self.MusicAllTimer.textColor = [UIColor grayColor];
    self.MusicAllTimer.text = @"00:00";
    self.MusicAllTimer.font = [UIFont systemFontOfSize:17];
    
    
    // 喜欢按钮
    self.likeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.visualEfView addSubview:_likeButton];
    _likeButton.frame = CGRectMake((WIDTH - 40 * wt - 40 * wt) / 2, _singerLabel.frame.size.height + _singerLabel.frame.origin.y + 25 * ht, 40 * wt, 40 * wt);
    [_likeButton setBackgroundImage:[UIImage imageNamed:@"iconfont-shoucangshi"] forState:UIControlStateNormal];
    [_likeButton addTarget:self action:@selector(likeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    //上一首按钮
    self.upButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.visualEfView addSubview:_upButton];
    _upButton.frame = CGRectMake(((WIDTH  - 40 * wt) / 2 - 20 * wt - 40 * wt) / 2, _singerLabel.frame.size.height + _singerLabel.frame.origin.y + 25 * ht, 40 * wt, 40 * wt);
    [_upButton setBackgroundImage:[UIImage imageNamed:@"iconfont-shangyishou"] forState:UIControlStateNormal];
    [_upButton addTarget:self action:@selector(upAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    // 下一首按钮
    self.downButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.visualEfView addSubview:_downButton];
    _downButton.frame = CGRectMake(((WIDTH  - 40 * wt) / 2 + 20 * wt + (((WIDTH  - 40 * wt) - ((WIDTH  - 40 * wt) / 2 + 20 * wt)) - 40 * wt) / 2), _singerLabel.frame.size.height + _singerLabel.frame.origin.y + 25 * ht, 40 * wt, 40 * wt);
    [_downButton setBackgroundImage:[UIImage imageNamed:@"iconfont-xiayishou"] forState:UIControlStateNormal];
    [_downButton addTarget:self action:@selector(downAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    self.progressV = [[UIProgressView alloc] initWithProgressViewStyle:(UIProgressViewStyleBar)];
    _progressV.frame =  CGRectMake(20 * wt,  _visualEfView.frame.size.height - 40 * ht , _visualEfView.frame.size.width - 40 * wt, 40 * ht);
    
    // 改变默认高度
    _progressV.transform = CGAffineTransformMakeScale(1.0f, 3.0f);
    _progressV.backgroundColor = [UIColor clearColor];
    _progressV.progressImage = [UIImage imageNamed:@"22.jpg"];
    _progressV.trackTintColor = [UIColor clearColor];
    [self.visualEfView addSubview:_progressV];

    
    
    //   // 0.1秒回调
    LY_sharePlayeMusicHelp.playTimerBlock = ^(CGFloat timer){
        
        //播放时间
        self.MusicCurrentTimer.text = [self timeToString:timer]; //调用方法，赋值
        //总时间
        self.MusicAllTimer.text = [self timeToString:LY_sharePlayeMusicHelp.sumtime - timer];
        [self playTimer1:timer]; //调用方法
        
    };

    
}

/** 下载过了 */
- (void)didDownLoad:(UIButton *)button {
    
    LYDownLoadViewController *downLoad = [[LYDownLoadViewController alloc] init];
    [self.navigationController pushViewController:downLoad animated:YES];
    
    [_musicView setHidden:YES];
    [_leftTableView setHidden:NO];
    [_rightTableView setHidden:NO];
    _rightTableView.alpha = 1;
    _leftTableView.alpha = 1;
    _isFirst = NO;
    
}


/** 下载 */
- (void)downLoad:(UIButton *)button {
    
    NSLog(@"下载");
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSDictionary *dic = [defaults objectForKey:@"model1"];
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"请选择下载内容" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"流畅品质" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//        // 禁止重复下载
//        if (self.isNowDownload) return;
//        
//        
//        self.nowDownload = YES;
        
        [self downLoading:dic[@"music"] name:dic[@"singName"] singerName:dic[@"singerName"] str:@"m4a"];
        
        
        
    }];
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"标准品质" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        
        [self downLoading:dic[@"Bmusic"] name:dic[@"singName"] singerName:dic[@"singerName"] str:@"mp3"];
        
    }];
    UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"超高品质" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        [self downLoading:dic[@"Hmusic"] name:dic[@"singName"] singerName:dic[@"singerName"] str:@"mp3"];
        
    }];
    
    
    UIAlertAction *action4 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
        
        
    }];
    [alert addAction:action];
    [alert addAction:action2];
    [alert addAction:action3];
    [alert addAction:action4];
    
    [self presentViewController:alert animated:YES completion:^{
        
    }];

    
}

- (void)downLoading:(NSString *)url name:(NSString *)name singerName:(NSString *)singerName str:(NSString *)str {
    
    
    NSLog(@"%@, %@, %@", url, name, singerName);
    
    if (url == NULL) {
        
        [JCAlertView showOneButtonWithTitle:@"对不起" Message:@"由于版权问题 暂不支持下载" ButtonType:JCAlertViewButtonTypeDefault ButtonTitle:@"确定" Click:^{
            
        }];
    }else {
        
        // 下载
        self.operation1 = [LHYDownLoadManager downloadFileWithURLString:url cachePath:[NSString stringWithFormat:@"%lu.mp3", (unsigned long)[name hash]] progress:^(CGFloat progress, CGFloat totalMBRead, CGFloat totalMBExpectedToRead) {
    
            NSLog(@"Task1 -> progress: %.2f -> download: %fMB -> all: %fMB", progress, totalMBRead, totalMBExpectedToRead);
    
            self.progressV.progress = progress;
    
    
        } success:^(AFHTTPRequestOperation *operation, id responseObject) {
    
            NSLog(@"Task1 -> Download finish");
            NSArray *pathArr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            // document路径
            NSString *documentPath = [pathArr lastObject];
            NSLog(@"%@", documentPath);
    
            // 把字典写入
            NSDictionary *dic = @{@"name": name,
                                  @"singerName" : singerName,
                                  @"song" : url };
            // 拼接一个字典路径
            NSString *dicPath = [documentPath stringByAppendingPathComponent:@"dic.list"];
            
            NSArray *arr = [NSArray arrayWithContentsOfFile:dicPath];
            NSMutableArray *array = [NSMutableArray arrayWithArray:arr];
            
            [array addObject:dic];
            
            BOOL result3 = [array writeToFile:dicPath atomically:YES];
        
    
            if (result3) {
                NSLog(@"写入成功");
                
                [JCAlertView showOneButtonWithTitle:@"下载成功" Message:nil ButtonType:JCAlertViewButtonTypeDefault ButtonTitle:@"确定" Click:^{
                    
                    [_didDownButton setHidden:YES];
                    [self noOrYesDownLoad];
                }];
                
                
            }else {
                NSLog(@"写入错误");
            }
            _progressV.alpha = 0;
    
    
    
    
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    
            if (error.code == -999) NSLog(@"Task1 -> Maybe you pause download.");
            
            NSLog(@"Task1 -> %@", error);
        }];
    }

    
}


//0.1秒block回调的方法
- (void)playTimer1:(CGFloat)timer{
    [self imgViewStop];
    self.timerSlder.value = timer / LY_sharePlayeMusicHelp.sumtime; //给滑竿赋值
    [self imgViewStart];
}

#pragma mark 获取字符串时间
- (NSString *)timeToString:(CGFloat)time{
    
    NSInteger minutes = (NSInteger)time / 60; //分钟
    NSInteger seconds = (NSInteger)time % 60; //秒
    //转换为string
    NSString *string = [NSString stringWithFormat:@"%02ld:%02ld",(long)minutes,(long)seconds];
    
    return string;
}



/** 上一曲点击 */
- (void)upAction:(UIButton *)button {
    
   
    _index--;
    if (_index < 0) {
        _index = _playArr.count - 1;
        LYDayMusicModel *model = _playArr[_index];
        [self change:model];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"huan" object:model];
        // 记录当前的歌曲
       NSDictionary *dic= [NSDictionary dictionaryWithObjectsAndKeys:model.singerName, @"singName", model.name, @"singerName", model.picUrl, @"pic", model.audition, @"music", model.Baudition, @"Bmusic", model.Haudition, @"Hmusic", nil];
        [[NSUserDefaults standardUserDefaults] setObject:dic forKey:@"model1"];
        
//        [[NSUserDefaults standardUserDefaults] setObject:model.Baudition forKey:@"B"];
//        [[NSUserDefaults standardUserDefaults] setObject:model.Haudition forKey:@"H"];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"huan1" object:dic];


    }else {
        
        LYDayMusicModel *model = _playArr[_index];
        [self change:model];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"huan" object:model];
        // 记录当前的歌曲
        NSDictionary *dic= [NSDictionary dictionaryWithObjectsAndKeys:model.singerName, @"singName", model.name, @"singerName", model.picUrl, @"pic", model.audition, @"music", model.Baudition, @"Bmusic", model.Haudition, @"Hmusic", nil];
        [[NSUserDefaults standardUserDefaults] setObject:dic forKey:@"model1"];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"huan1" object:dic];
//        [[NSUserDefaults standardUserDefaults] setObject:model.Baudition forKey:@"B"];
//        [[NSUserDefaults standardUserDefaults] setObject:model.Haudition forKey:@"H"];



    }
    
    [_didDownButton setHidden:YES];
    [_loadButton setHidden:YES];
     [self noOrYesDownLoad];
    [_buttomTableView reloadData];
}

/** 下一曲点击 */
- (void)downAction:(UIButton *)button {
    
    
    
    _index++;
    
    // 判断下标
    if (_index < _playArr.count) {
        
        LYDayMusicModel *model = _playArr[_index];
        [self change:model];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"huan" object:model];
        
        // 记录当前的歌曲
       NSDictionary *dic= [NSDictionary dictionaryWithObjectsAndKeys:model.singerName, @"singName", model.name, @"singerName", model.picUrl, @"pic", model.audition, @"music", model.Baudition, @"Bmusic", model.Haudition, @"Hmusic", nil];
        [[NSUserDefaults standardUserDefaults] setObject:dic forKey:@"model1"];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"huan1" object:model];
//        [[NSUserDefaults standardUserDefaults] setObject:model.Baudition forKey:@"B"];
//        [[NSUserDefaults standardUserDefaults] setObject:model.Haudition forKey:@"H"];



        
        // 音乐没有了
    }else {
        
        _index = 0;
        
        LYDayMusicModel *model = _playArr[_index];
        [self change:model];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"huan" object:model];

        // 记录当前的歌曲
       NSDictionary *dic= [NSDictionary dictionaryWithObjectsAndKeys:model.singerName, @"singName", model.name, @"singerName", model.picUrl, @"pic", model.audition, @"music", model.Baudition, @"Bmusic", model.Haudition, @"Hmusic", nil];
        [[NSUserDefaults standardUserDefaults] setObject:dic forKey:@"model1"];
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"huan1" object:model];
//        [[NSUserDefaults standardUserDefaults] setObject:model.Baudition forKey:@"B"];
//        [[NSUserDefaults standardUserDefaults] setObject:model.Haudition forKey:@"H"];


        
        
    }
    [_didDownButton setHidden:YES];
    [_loadButton setHidden:YES];
    [self noOrYesDownLoad];
    [_buttomTableView reloadData];
}

/** 换曲改变 */
- (void)change:(LYDayMusicModel *)model {
    
    
    [LY_sharePlayeMusicHelp playMusicMp3Url:model.audition];
    [self.bigImgView sd_setImageWithURL:[NSURL URLWithString:model.picUrl] placeholderImage:[UIImage imageNamed:@"00"]];
    _singerLabel.text = [NSString stringWithFormat:@"作者 : %@", model.singerName];
    _songLabel.text = model.name;
    [self imgViewStart];
}

- (void)sliderAction:(UISlider *)slider {
    
    
    [LY_sharePlayeMusicHelp seekToTime:slider.value];
    
}
// 图片停止转
- (void)imgViewStop {
    
    
    CFTimeInterval stopTime = [self.imgView.layer convertTime:CACurrentMediaTime() fromLayer:nil];//CACurrentMediaTime()绝对时间,也就是持续 时间,一直走.
    //设置动画速度
    self.imgView.layer.speed = 0;
    //保存时间的偏移量
    self.imgView.layer.timeOffset = stopTime;
    
}

// 图片停止转
- (void)bigImgViewStop {
    
    
    CFTimeInterval stopTime = [self.bigImgView.layer convertTime:CACurrentMediaTime() fromLayer:nil];//CACurrentMediaTime()绝对时间,也就是持续 时间,一直走.
    //设置动画速度
    self.bigImgView.layer.speed = 0;
    //保存时间的偏移量
    self.bigImgView.layer.timeOffset = stopTime;
    
}
// 图片开始转
- (void)bigImgViewStart {
    
    //速度设置为1
    self.bigImgView.layer.speed = 1;
    self.bigImgView.layer.beginTime = 0; //把原来的,上次的开始时间清零
    
    //找到时间偏移量
    CFTimeInterval stopTime = self.bigImgView.layer.timeOffset;
    //设置开始的时间
    self.bigImgView.layer.beginTime = [self.bigImgView.layer convertTime:CACurrentMediaTime() fromLayer:nil] - stopTime;
}

// 图片开始转
- (void)imgViewStart {
    
    //速度设置为1
    self.imgView.layer.speed = 1;
    self.imgView.layer.beginTime = 0; //把原来的,上次的开始时间清零
    
    //找到时间偏移量
    CFTimeInterval stopTime = self.imgView.layer.timeOffset;
    //设置开始的时间
    self.imgView.layer.beginTime = [self.imgView.layer convertTime:CACurrentMediaTime() fromLayer:nil] - stopTime;
}

#pragma mark - 喜欢的按钮
- (void)likeButtonAction:(UIButton *)button {
    
    
    
}

#pragma mark - 数据解析
- (void)dataHandle {
    
    [XRAFNetworkTool GETUrl:@"http://api.fm.ttpod.com/radio?app=ttpod&v=v8.1.5.2016022418&user_id=0&mid=iPhone5C&f=f320&s=s310&imsi=&hid=&splus=8.4.1&active=1&net=2&openudid=2b2eba0e983843cf5ebcfa76b63e1682221e74ef&idfa=C142307D-73E9-409F-88B5-2F7B28503941&utdid=VkKgUwkPrlsDAINyD9AzAIoe&alf=201200&bundle_id=com.ttpod.music&latitude=&longtitude=" body:nil headFile:nil response:XRJSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSArray *arr = responseObject[@"data"];
        self.titleArr = [LYDayTitleModel modelWithArray:arr];
        
        NSArray *arr1 = responseObject[@"data"][0][@"data"];
        self.songArr = [LYDayRightModel modelWithArray:arr1];
        [_leftTableView reloadData];
        [_rightTableView reloadData];
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
}

- (void)musicDataHandle {
    [XRAFNetworkTool GETUrl:[NSString stringWithFormat:@"http://api.fm.ttpod.com/radio/%@/songs?page_num=1&page_size=5&userid=0", _idStr] body:nil headFile:nil response:XRJSON success:^(NSURLSessionDataTask *task, id responseObject) {
        
        NSArray *arr = responseObject[@"data"];
        self.playArr = [LYDayMusicModel modelWithArray:arr];
        
        
        if (_play == YES) {
            
        
        LYDayMusicModel *model = _playArr[0];
        _singLabel.text = model.name;
        _authorLabel.text = model.singerName;
        if (arr[0] != NULL) {
            
        // 图片赋值 旋转
        NSString *str = arr[0][@"picUrl"];
        [_imgView sd_setImageWithURL:[NSURL URLWithString:str]];
        
        [self performSelector:@selector(startAnimate) withObject:self afterDelay:0.1];
        
        // 音乐播放
        NSArray *array = arr[0][@"auditionList"];
        [LY_sharePlayeMusicHelp playMusicMp3Url:array[0][@"url"]];
            self.index = 0;
            

        }
    // 记录当前的歌曲
        NSDictionary *dic= [NSDictionary dictionaryWithObjectsAndKeys:model.singerName, @"singName", model.name, @"singerName", model.picUrl, @"pic", model.audition, @"music", model.Baudition, @"Bmusic", model.Haudition, @"Hmusic", nil];
         [[NSUserDefaults standardUserDefaults] setObject:dic forKey:@"model1"];
//            [[NSUserDefaults standardUserDefaults] setObject:model.Baudition forKey:@"B"];
//            [[NSUserDefaults standardUserDefaults] setObject:model.Haudition forKey:@"H"];

        
        }
        
        _play = NO;
        [_listTableView reloadData];

        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
    
    
    
    
}


-(void)startAnimate{
    
    //CALyer动画 core Animation 核心动画(transform.rotation.z沿着z轴旋转,可以自己改下x, 或y 看看效果)animationWithKeyPath根据什么进行动画
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    //旋转的起始值
    animation.fromValue = [NSNumber numberWithFloat:0];
    //旋转的结束值(M_PI 为: 180度)
    animation.toValue = [NSNumber numberWithFloat:M_PI * 2];
    //重复次数(NSIntegerMax最大数,无限了.)
    animation.repeatCount = NSIntegerMax;
    //是否自动回到原来位置
    //    animation.autoreverses = NO;
    //是否按照结束位置继续旋转
    //    animation.cumulative = YES;
    //动画时长
    animation.duration = 20;
    [self.imgView.layer addAnimation:animation forKey:@"动画标记"];
    
    [self.bigImgView.layer addAnimation:animation forKey:@"哈哈"];
    
}

- (void)viewWillAppear:(BOOL)animated {
    [_buttomTableView setHidden:NO];
    if ([LY_sharePlayeMusicHelp isPlay]) {
        
        [self imgViewStart];
    }else {
        [self imgViewStop];
    }
    
    
    
    NSMutableArray *arrTitle = [NSMutableArray array];
    self.arrDownLoad = [self getArr];
    
    for (NSDictionary *dic in self.arrDownLoad) {
        
        [arrTitle addObject:dic[@"singerName"]];
        
    }
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSDictionary *dic = [defaults objectForKey:@"model1"];
    
    if ([arrTitle containsObject:dic[@"singerName"]]) {
        
        //        self.isDownLoad = YES;
        
        _loadButton.alpha = 0;
        [_loadButton setHidden:YES];
        
        self.didDownButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.visualEfView addSubview:_didDownButton];
        _didDownButton.frame = CGRectMake(WIDTH - 80 * wt, _singerLabel.frame.origin.y, 20 * wt, 20 * wt);
        [_didDownButton setBackgroundImage:[UIImage imageNamed:@"iconfont-liangkehongxin"] forState:UIControlStateNormal];
        [_didDownButton addTarget:self action:@selector(didDownLoad:) forControlEvents:UIControlEventTouchUpInside];
    }else {
        //        self.isDownLoad = NO;
        
        _didDownButton.alpha = 0;
        [_didDownButton setHidden:YES];
        self.loadButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.visualEfView addSubview:_loadButton];
        _loadButton.frame = CGRectMake(WIDTH - 80 * wt, _singerLabel.frame.origin.y, 20 * wt, 20 * wt);
        [_loadButton setBackgroundImage:[UIImage imageNamed:@"iconfont-download"] forState:UIControlStateNormal];
        [_loadButton addTarget:self action:@selector(downLoad:) forControlEvents:UIControlEventTouchUpInside]
        ;
        
        
    }

    
    
    
}



// 从本地获取下载的数组
- (NSMutableArray *)getArr {
    
    NSArray *pathArr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSLog(@"%@", pathArr);
    NSString *documentPath = [pathArr lastObject];
    NSString *arrPath = [documentPath stringByAppendingPathComponent:@"dic.list"];
    
    NSArray *arr = [NSArray arrayWithContentsOfFile:arrPath];
    NSMutableArray *arrM = [NSMutableArray arrayWithArray:arr];
    
    return arrM;
    
}


- (void)viewWillDisappear:(BOOL)animated {
    [_buttomTableView setHidden:YES];
    [LY_sharePlayeMusicHelp pause];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
